package com.bookrecomm.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 认证测试工具类
 * 用于测试密码加密和验证
 */
public class AuthenticationTest {
    
    public static void main(String[] args) {
        // 创建BCrypt密码编码器
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        
        // 测试密码
        String rawPassword = "123456";
        
        // 加密密码
        String encodedPassword = encoder.encode(rawPassword);
        System.out.println("原始密码: " + rawPassword);
        System.out.println("加密后密码: " + encodedPassword);
        
        // 验证密码
        boolean matches = encoder.matches(rawPassword, encodedPassword);
        System.out.println("密码验证结果: " + matches);
        
        // 测试数据库中可能存在的密码格式
        String[] dbPasswords = {
            "$2a$10$EuMhXS.OMxs9/AX8eDUyXe6HkUXkNZ8zXZLkRAJNL/xtVEKdUACyW",
            "$2a$10$NlBC84MVb7F/d7D4G/onu.xMXU0MSn/PjGIo5kUeRsxg2iVZ9tkoS",
            "$2a$10$8CU8yBnwCWN4U.bcq7ZigeJCmxQ.JpZDMyI.wSBBIHxYCnLRQZDFu"
        };
        
        // 测试不同的密码格式
        for (String dbPassword : dbPasswords) {
            boolean dbMatches = encoder.matches(rawPassword, dbPassword);
            System.out.println("数据库密码: " + dbPassword);
            System.out.println("验证结果: " + dbMatches);
        }
        
        // 生成SQL语句用于重置密码
        System.out.println("\n-- 重置用户密码SQL:");
        System.out.println("UPDATE users SET password = '" + encodedPassword + "' WHERE username = 'admin';");
    }
}
